<?php
// +----------------------------------------------------------------------
// | astp [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 公众号
// +----------------------------------------------------------------------
namespace app\wewhat\controller;

use think\Controller;
use app\wewhat\controller\Accept;
use think\facade\Config;

class Index extends Controller
{
  public function initialize()
  {
    $accept = new Accept();
    if(!empty(input('get.echostr'))){
      $this->index();
    } else {
      $accept->acceptMsg();
    }
  }

  public function index()
  {
    $input = request()->param();
    $echostr = $input['echostr'];
    $signature = $input['signature'];
    unset($input['echostr'],$input['signature']);
    $input['token'] = Config::get('wewhat.TOKEN');
    $tmpStr = implode( $input );
    $tmpStr = sha1( $tmpStr );
    if( $tmpStr == $signature ){
      echo $echostr;
      exit;
    } else {
      return false;
    }
  }

}